import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.ResultActions;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;

@SpringBootTest
@AutoConfigureMockMvc
public class Controller2 extends BaseTest {
    @Autowired
    private MockMvc mockMvc;

    //用户查询
    @Test
    public void apiTest() throws Exception {
        //构建请求
        MockHttpServletRequestBuilder request = MockMvcRequestBuilders.get("/fail");
        //发送请求，获取结果
        ResultActions perform = mockMvc.perform(request);
        //请求结果检验
        perform.andExpect(MockMvcResultMatchers.status().is(401));
        //表示执行后响应结果
        MvcResult mvcResult = perform.andReturn();
        MockHttpServletResponse response = mvcResult.getResponse();
    }
}
